import multiprocessing
from time import sleep

from loguru import logger


def work():
    for _ in range(10):
        logger.info('工作中...')
        sleep(0.2)


if __name__ == '__main__':
    work_process = multiprocessing.Process(target=work)
    # 设置守护主进程，主进程不再等待子进程结束后再结束
    work_process.daemon = True
    work_process.start()

    # 延时1秒
    sleep(1)
    work_process.terminate()
    logger.info('主进程执行完毕！')
    # 总结：主进程会等待所有的子进程执行结束后再结束
